package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;


import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 查询支付和未支付的订单
     * @param userId
     * @return
     * @throws Exception
     */
    public List<Orders> orderList(String userId);

    /**
     * 下单
     * @param orders
     * @return
     * @throws Exception
     */
    @Insert("insert into orders(userId,businessId,orderDate,orderTotal,daId,orderState) value(#{userId},#{businessId},#{orderDate},#{orderTotal},#{daId},0)")
    @Options(useGeneratedKeys = true,keyProperty = "orderId",keyColumn = "orderId")
    public int creatOrder(Orders orders);

    /**
     * id查订单
     * @param
     * @return
     * @throws Exception
     */
    public Orders orderById(Integer orderId);

    /**
     * 支付完成
     * @param
     * @return
     * @throws Exception
     */
    @Update("update orders set orderState = 1 where orderId = #{orderId}")
    public int payOver(Integer orderId);
}
